﻿using System.Windows.Forms;
using System.Collections.Generic;
using System.Collections;
using System;
using AutoIt_Elements.Core.LanguageManager;
using AutoIt_IDE;

namespace AutoIt_Elements.GUI
{
    public partial class LangEditor : Form
    {
        public LangEditor()
        {
            InitializeComponent();
        }

        public void LoadLanguageData(Language lang)
        {
            BindingSource bs = new BindingSource();
            foreach (KeyValuePair<String, String> kvp in lang.Tokens)
            {
                bs.Add(kvp);
            }

            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.AutoSize = true;
            dataGridView1.DataSource = bs;
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "Please select a valid AutoIt Elements Language File";
            ofd.Filter = "AE Language Files (*.xml)|*.xml";
            ofd.CheckFileExists = true;
            ofd.CheckPathExists = true;

            DialogResult ds = ofd.ShowDialog();
            if (ds == System.Windows.Forms.DialogResult.OK)
            {
                if (ofd.FileName != String.Empty)
                {
                    Language lang = Program.langManager.LoadLanguage(ofd.FileName);
                    LoadLanguageData(lang);
                }
            }
        }
    }
}
